package org.windblog.api.template;

import java.util.*;
public class ParamParser {

	Map<String,Object> params = new HashMap<String, Object>();
	
	public void setParameter(String name,Object value) {
		params.put(name, value);
	}
	
	public Object getParameter(String name) {
		return params.get(name);
	}

	public void parse(String param) {
		if(param.length()==0)
			return;
		String[] kvs = param.split("\\&");
		for(String kv : kvs)
		{
			String k = kv.split("=")[0];
			String v = kv.split("=")[1];
			if(params.containsKey(k))
			{
				params.put(k, v);
			}else{
				throw new RuntimeException("The parameter "+k+" is not allowed.");
			}
		}
	}


}
